/**
 * $Id: NeighbouringNumbers.java 69 2012-12-11 11:54:51Z Denis.Skalsky@gmail.com $
 */
package com.globallogic.skalskyy.javabasic.neighbouringnumbers;

import com.globallogic.skalskyy.javabasic.inputdata.ConsoleReader;
import com.globallogic.skalskyy.javabasic.inputdata.DataValidator;

/** 
* NeighbouringNumbers finds index of neighboring numbers.
* @author $Author: Denis.Skalsky@gmail.com $
* @version $Revision: 47 $
*/
public class NeighbouringNumbers {
	
	/** Getting inputted data. */
	private DataValidator dataValidator = new DataValidator();
	
	public void setConsoleReader() {
		this.dataValidator.setIncomingData(
				new ConsoleReader(ConsoleReader.ConsoleCommandPrompt.NEIGHBOURING));
	}
	
	/** Getting inputted array of integer. */
	public int[] getArrayOfInt() {
		return dataValidator.getListOfPositiveIntValue();
	}
	
	/**
	 * Find index of neighbouring numbers.
	 * @param args array of inputted integer
	 * @return int index of number with min distance 
	 */
	public int getIndexWithMinDistance(int[] args) {
		int result = -1;
		int minDistance = -1;
		
		for (int i = 0; i < args.length; i++) {
			for (int j = 0; j < args.length; j++) {
				if (i == j) {
					continue;
				};
				
				if ((result == -1) || (minDistance > Math.abs(args[i] - args[j]))) {
					minDistance = Math.abs(args[i] - args[j]);
					result = i;
				};
			};
		};
		
		return result;
	}
}
